load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")

package(default_visibility = ["//visibility:public"])

rust_library(
    name = "admin",
    srcs = glob(["src/**/*.rs"]),
    crate_name = "ic_admin",
    version = "0.0.1",
    deps = [
        # Keep sorted.
        "//rs/crypto/utils/threshold_sig_der",
        "//rs/protobuf",
        "//rs/registry/client",
        "//rs/registry/keys",
        "//rs/registry/local_store",
        "//rs/registry/nns_data_provider_wrappers",
        "//rs/registry/routing_table",
        "//rs/types/base_types",
        "//rs/types/types",
        "@crate_index//:prost",
        "@crate_index//:tokio",
        "@crate_index//:url",
    ],
)

cargo_build_script(
    name = "build_script",
    srcs = ["build.rs"],
    build_script_env = {
        "VERSION_TXT_PATH": "$(location //bazel:version.txt)",
        "COMMIT_DATE_ISO_8601_TXT_PATH": "$(location //bazel:commit_date_iso_8601.txt)",
    },
    data = [
        "//bazel:commit_date_iso_8601.txt",
        "//bazel:version.txt",
    ],
)

rust_binary(
    name = "ic-admin",
    testonly = True,
    srcs = glob(["bin/**/*.rs"]),
    proc_macro_deps = [
        # Keep sorted.
        "//rs/registry/admin-derive",
        "@crate_index//:async-trait",
        "@crate_index//:strum_macros",
    ],
    deps = [
        # Keep sorted.
        ":admin",
        ":build_script",
        "//rs/canister_client",
        "//rs/canister_client/sender",
        "//rs/crypto/internal/crypto_lib/types",
        "//rs/crypto/utils/threshold_sig_der",
        "//rs/http_utils",
        "//rs/interfaces/registry",
        "//rs/nervous_system/clients",
        "//rs/nervous_system/common",
        "//rs/nervous_system/common/test_keys",
        "//rs/nervous_system/humanize",
        "//rs/nervous_system/proto",
        "//rs/nervous_system/root",
        "//rs/nns/cmc",
        "//rs/nns/common",
        "//rs/nns/constants",
        "//rs/nns/governance/api",
        "//rs/nns/handlers/root/impl:root",
        "//rs/nns/init",
        "//rs/nns/sns-wasm",
        "//rs/nns/test_utils",
        "//rs/prep",
        "//rs/protobuf",
        "//rs/registry/canister",
        "//rs/registry/client",
        "//rs/registry/helpers",
        "//rs/registry/keys",
        "//rs/registry/local_store",
        "//rs/registry/nns_data_provider",
        "//rs/registry/nns_data_provider_wrappers",
        "//rs/registry/provisional_whitelist",
        "//rs/registry/routing_table",
        "//rs/registry/subnet_features",
        "//rs/registry/subnet_type",
        "//rs/registry/transport",
        "//rs/sns/init",
        "//rs/types/management_canister_types",
        "//rs/types/types",
        "@crate_index//:anyhow",
        "@crate_index//:base64",
        "@crate_index//:candid",
        "@crate_index//:chrono",
        "@crate_index//:clap",
        "@crate_index//:futures",
        "@crate_index//:hex",
        "@crate_index//:ic-btc-interface",
        "@crate_index//:indexmap",
        "@crate_index//:itertools",
        "@crate_index//:maplit",
        "@crate_index//:prost",
        "@crate_index//:serde",
        "@crate_index//:serde_json",
        "@crate_index//:strum",
        "@crate_index//:tempfile",
        "@crate_index//:tokio",
        "@crate_index//:url",
    ],
)

rust_test(
    name = "ic-admin_unit_test",
    crate = ":ic-admin",
    deps = [
        "@crate_index//:pretty_assertions",
    ],
)

rust_test(
    name = "integration_tests",
    srcs = glob(["tests/**/*.rs"]),
    data = [
        "//rs/ledger_suite/icp/ledger:ledger-canister-wasm",
        "//rs/nns/governance:governance-canister",
        "//rs/nns/handlers/lifeline/impl:lifeline_canister",
        "//rs/nns/handlers/root/impl:root-canister",
        "//rs/nns/sns-wasm:sns-wasm-canister",
        "//rs/registry/canister:registry-canister",
        "//rs/registry/canister:registry-canister-test",
    ],
    env = {
        "GOVERNANCE_CANISTER_WASM_PATH": "$(rootpath //rs/nns/governance:governance-canister)",
        "REGISTRY_CANISTER_WASM_PATH": "$(rootpath //rs/registry/canister:registry-canister)",
        "REGISTRY_CANISTER_TEST_WASM_PATH": "$(rootpath //rs/registry/canister:registry-canister-test)",
        "LEDGER_CANISTER_WASM_PATH": "$(rootpath //rs/ledger_suite/icp/ledger:ledger-canister-wasm)",
        "LIFELINE_CANISTER_WASM_PATH": "$(rootpath //rs/nns/handlers/lifeline/impl:lifeline_canister)",
        "SNS_WASM_CANISTER_WASM_PATH": "$(rootpath //rs/nns/sns-wasm:sns-wasm-canister)",
        "ROOT_CANISTER_WASM_PATH": "$(rootpath //rs/nns/handlers/root/impl:root-canister)",
        "POCKET_IC_BIN": "$(rootpath //rs/pocket_ic_server:pocket-ic-server)",
        "IC_ADMIN_BIN": "$(rootpath //rs/registry/admin:ic-admin)",
    },
    deps = [
        # Keep sorted.
        ":admin",
        ":ic-admin",
        "//packages/pocket-ic",
        "//rs/nervous_system/agent",
        "//rs/nervous_system/chunks",
        "//rs/nervous_system/common/test_keys",
        "//rs/nervous_system/integration_tests:nervous_system_integration_tests",
        "//rs/nns/constants",
        "//rs/nns/test_utils",
        "//rs/pocket_ic_server:pocket-ic-server",
        "//rs/registry/canister/api",
        "//rs/registry/local_store",
        "//rs/types/base_types",
        "@crate_index//:candid",
        "@crate_index//:tempfile",
        "@crate_index//:tokio",
        "@crate_index//:url",
    ],
)
